package com.xing.crm.web.controller;

import com.xing.crm.pojo.PageResult;
import com.xing.crm.pojo.ProRole;
import com.xing.crm.pojo.User;
import com.xing.crm.service.ProRoleService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author Mr.L
 * @version V1.0
 * @date 2021年08月04日 17:00
 */
@RequestMapping("/role")
@Controller
public class ProRoleController {
	
	@Resource
	private ProRoleService proRoleService;
	
	@RequestMapping("/listPage")
	public String list(Model model)
	{
		return "admin/sys/list";
	}
	
	@ResponseBody
	@RequestMapping("/list")
	public PageResult<ProRole> list(@RequestParam(required = false, defaultValue = "1") int page,
									@RequestParam(required = false, defaultValue = "10") int limit, ProRole proRole)
	{
		return proRoleService.list(page, limit, proRole);
	}
	
	@ResponseBody
	@RequestMapping("/edit")
	public Map<String, Object> edit(ProRole proRole, HttpSession session)
	{
		User user = (User) session.getAttribute("user");
		proRole.setModifier(String.valueOf(user.getId()));
		return proRoleService.edit(proRole);
	}
	
	@ResponseBody
	@RequestMapping("/delete")
	public Map<String, Object> delete(Integer id)
	{
		return proRoleService.delete(id);
	}
}
